package com.lcf.myspringboot.controller;

import com.lcf.myspringboot.entity.User;
import com.lcf.myspringboot.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * Created by lancf on 2019/6/27.
 */
@RestController
@Slf4j
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/aa")
    public String test1() {
        return "hello";
    }

    @GetMapping("/queryUserById")
    public User queryUserById(String id) {
        User user = userService.queryUserById(id);
        return user;
    }

    @GetMapping("/queryUserById/{id}")
    public String queryUserById2(@PathVariable("id") String id) {
        User user = userService.queryUserById(id);
        return user.getName();
    }

    @GetMapping("/insertUser/{name}/{age}")
    public Integer insertUser(@PathVariable("name") String name, @PathVariable("age") Integer age) {
        Integer integer = userService.insertUser(name, age);
        return integer;
    }

}
